package com.example.nio.example;

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class ChannelTranferExample {

    public static void transfer()throws Exception{
        RandomAccessFile fromFile = new RandomAccessFile("/Users/arry/Desktop/code/nio/src/main/java/com/example/nio/data/from.txt", "rw");
        FileChannel      fromChannel = fromFile.getChannel();

        RandomAccessFile toFile = new RandomAccessFile("/Users/arry/Desktop/code/nio/src/main/java/com/example/nio/data/to.txt", "rw");
        FileChannel toChannel = toFile.getChannel();

        long position = 0;
        long count = fromChannel.size();

        toChannel.transferFrom(fromChannel,position, count);
    }
    public static void main(String[] args) throws Exception {
        transfer();
    }
}
